include<BOSL2/std.scad>
include<BOSL2/gears.scad>
include<tools/util.scad>
$fn=100;

mod=1.5; //模数

 PA=20;//压力角
 face=15;//厚度
 gap=2;//空隙
 
 //4x5x5,15:60 15:75 15:75
cteeth=60; //齿数
pteeth=15;//齿数
dteeth=75;

//半径们
pr_60 = pitch_radius(mod=mod, teeth=cteeth);
pr_15 = pitch_radius(mod=mod, teeth=pteeth);
pr_75 = pitch_radius(mod=mod, teeth=dteeth);


translate([-(pr_60+pr_15),0,0])spur_gear_15();
translate([-(pr_60+pr_15),0,0])rod_2();
spur_gear_60();
rod_1();
translate([0,0,-(face+gap)])spur_gear_15();
translate([0,pr_15+pr_75,-(face+gap)])spur_gear_75();
translate([0,pr_15+pr_75,0])spur_gear_15();
translate([0,pr_15+pr_75,0])rod_1();
translate([0,pr_75*2+pr_15*2,0])spur_gear_75();
translate([0,pr_75*2+pr_15*2,0])rod_3();
shell();
translate([100,0,0])stick_std();


module moto_axis_mask(){
    intersection(){
            cube([5.6,3.9,6],center=true);
            translate([0,0,-3])cylinder(h=6,d=5.6);
        }
} 
module moto_axis(){
    intersection(){
            cube([5.6,3.6,8],center=true);
            translate([0,0,-4])cylinder(h=8,d=5.4);
      }    
} 
module spur_gear_60(){

    difference(){
    spur_gear(mod=mod, teeth=cteeth,pressure_angle=PA, thickness=face,gear_spin=270/cteeth);
    cube([10,10,face],center=true);
    }
}


module spur_gear_15(){
union(){
        difference(){
        spur_gear(mod=mod, teeth=pteeth,pressure_angle=PA, thickness=face);
        cube([10,10,face],center=true);
        }
        //打印用支撑条
        translate([0,0,-face/2+0.1 ])cube([6,10,0.2],center=true);
    }
}
module spur_gear_75(){
 
    difference(){
    spur_gear(mod=mod, teeth=dteeth,pressure_angle=PA, thickness=face);
    cube([10,10,face],center=true);
    }
}

module rod_1(){
    difference(){
        translate([0,0,-face/2])union(){
            //2*face+gap+2*4.6
            cube([9.6,9.6,45],center=true);
            translate([0,0,22.5])link_stick();
            translate([0,0,-22.5])rotate([180,0,0])link_stick();
            translate([0,0,32.5])cylinder(h=20,d=9.6);
            translate([0,0,-47.5])cylinder(h=15,d=9.6);
        }
        translate([-2.5,-5,face/2+ 1])cube([5,10,5]);
        translate([-2.5,-5,-(face/2+5+1)])cube([5,10,5]);
        translate([-2.5,-5,-(face*1.5+gap+5+1)])cube([5,10,5]);
    }
}

module link_stick(){
    hull(){
        translate([0,0,2])cube([9.6,9.6,4],center=true);
        translate([0,0,4])cylinder(h=6,d=9.6);
    }
}

module rod_2(){
    difference(){
        rod_1();
        translate([0,0,52.5-face/2-3])moto_axis_mask();
    }
}

module rod_3(){
    rod_1();
    translate([0,0,52.5-face/2+4])moto_axis();
}


module stick_std(){
    cube([4.6,4.6,11]);
}

module cy_socket(){
    difference(){
        cylinder(h=12,d=14);
        translate([0,0,2])cylinder(h=10,d=10);
    }
}
module shell(){
     zz=-55-3.5-2;
     zn=45-10;
     zps=[[0,0],[-(pr_60+pr_15),0],[0,pr_15+pr_75],[0,pr_75*2+pr_15*2]];
    difference(){
        union(){
            //底面
            translate([-80,-10,zz])cube([90,20,3.5]);
            translate([-10,10,zz])cube([20,140,3.5]);
            for(zp = zps){
                translate([zp[0],zp[1],zz+3.5])cylinder(h=12,d=14);
            }

            //顶面
     
               translate([-80,-10,zn])cube([90,20,10]);
               translate([-10,10,zn])cube([20,140,10]);
         }
        for(zp = zps){
            translate([zp[0],zp[1],zz+3.5+2])cylinder(h=101,d=10);
        }

    }
    
    //侧面
    translate([-80,-10,zz+3.5])cube([3.5,20,100-10+2]);
    //加强
    translate([-80+3.5,0,zz+3.5])d__tri_stiff(x=10,y=15,z=5);
    translate([-80+3.5,0,zn])rotate([180,0,0])d__tri_stiff(x=10,y=15,z=5);
}